<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('菜单流程配置') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('菜单名称')" prop="menuName">
        <el-input
          v-model="queryParams.menuName"
          :placeholder="$t('菜单名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('菜单标识')" prop="menuKey">
        <el-input
          v-model="queryParams.menuKey"
          :placeholder="$t('菜单标识')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('流程名称')" prop="procDefName">
        <el-input
          v-model="queryParams.procDefName"
          :placeholder="$t('流程名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('是否发布至流程工作台')" prop="whetherReleaseWorkbench">
        <el-select v-model="queryParams.whetherReleaseWorkbench" :placeholder="$t('请选择')" filterable>
          <el-option
            v-for="dict in sysYesOrNoOptions"
            :key="dict.dictValue"
            :label="$t(dict.dictLabel)"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['act:process:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >{{ $t("新增") }}</el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      tooltip-effect="darkTable"
      :data="wfMenuProcessList"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('菜单名称')" align="center" prop="menu.menuName">
        <template slot-scope="scope">
          {{ $t(scope.row.menu.menuName) }}
          <el-tooltip :content="scope.row.menuPath" placement="top">
            <i class="el-icon-question" />
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column :label="$t('菜单标识')" align="center" prop="menu.menuKey">
        <template slot-scope="scope">
          {{ $t(scope.row.menu.menuKey) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('流程名称')" align="center" prop="procDefName">
        <template slot-scope="scope">
          {{ $t(scope.row.procDefName) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否发布至流程工作台')" align="center" prop="whetherReleaseWorkbench" show-overflow-tooltip :formatter="whetherReleaseWorkbenchFormat" />
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['act:process:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['act:process:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改菜单流程配置对话框 -->
    <el-dialog :title="$t('菜单流程配置')" :close-on-click-modal="false" :visible.sync="open" width="50%">
      <wfMenuProcessForm ref="wfMenuProcessForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listWfMenuProcess,
  // getWfMenuProcess,
  delWfMenuProcess
  // saveWfMenuProcess,
  // updateWfMenuProcess
} from '@/api/act/process/wfMenuProcess'
import wfMenuProcessForm from './wfMenuProcessForm.vue'
export default {
  components: {
    wfMenuProcessForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 菜单流程配置表格数据
      wfMenuProcessList: [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        menuName: undefined,
        procDefName: undefined,
        whetherReleaseWorkbench: undefined,
        menuKey: undefined
      },
      wfMenuProcessData: {},
      sysYesOrNoOptions: [],
      // 表单参数
      form: {}
    }
  },
  created() {
    this.getList()
    this.getDicts('sys_yes_no').then(response => {
      this.sysYesOrNoOptions = response.data
    })
  },
  methods: {
    /** 查询菜单流程配置列表 */
    getList() {
      this.loading = true
      listWfMenuProcess(this.queryParams).then(response => {
        this.wfMenuProcessList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
    },
    // 是否发布至流程工作台字典翻译
    whetherReleaseWorkbenchFormat(row) {
      return this.selectDictLabel(this.sysYesOrNoOptions, row.whetherReleaseWorkbench)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true
      this.$nextTick(() => {
        this.$refs.wfMenuProcessForm.init(null)
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true
      this.$nextTick(() => {
        this.$refs.wfMenuProcessForm.init(row.id)
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return delWfMenuProcess(row.id)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        })
        .catch(function() {})
    }
  }
}
</script>
